#define _CRT_SECURE_NO_WARNINGS 1
#include "seqlist.h"
void SLInit(SL* pch)
{
	pch->array = (SLdatetype*)malloc(sizeof(SLdatetype) * int_capacity);
	assert(pch);
	pch->size = 0;
	pch->capacity = int_capacity;
}
void destroy(SL* pch)
{
	free(pch->array);
	pch->array = NULL;
	pch->size = pch->capacity = 0;
}
void checkcapacity(SL* pch)
{
	if (pch->size == pch->capacity)
	{
		SLdatetype* tmp = (SLdatetype*)malloc(sizeof(SLdatetype) * pch->capacity * 2);
		assert(tmp);
		pch->array = tmp;

	}
	pch->capacity *= 2;
}
void seqlistpushback(SL* pch, SLdatetype x)

{
	checkcapacity(pch);
	pch->array[pch->size++] = x;
}

void seqlistpopback(SL* pch)
{
	assert(pch->size > 0);
	pch->size--;
}
void seqlistprint(SL* pch)
{
	assert(pch);
	for (int i = 0;i < pch->size;i++)
	{
		printf("%d ", pch->array[i]);
	}
	printf("\n");
}
void seqlistpushfront(SL* pch, SLdatetype x)
{
	assert(pch);
	checkcapacity(pch);
	int end = pch->size - 1;
	while (end >= 0)
	{
		pch->array[end + 1] = pch->array[end];
		end--;
	}
	pch->array[0] = x;
	pch->size++;
}
void seqlistinsert(SL* pch, int pop, SLdatetype x)
{
	assert(pch);
	checkcapacity(pch);
	int end = pch->size - 1;
	while (end >= pop)
	{
		pch->array[end + 1] = pch->array[end];
		end--;
	}
	pch->array[pop] = x;
	pch->size++;
}
void seqlistpopfront(SL* pch)
{
	assert(pch);
	int end = 0;
	while (end < pch->size - 1)
	{
		pch->array[end] = pch->array[end + 1];
	}
	pch->size--;
}
SLdatetype seqlistfind(SL* pch, SLdatetype x)
{
	assert(pch);
	for (int i = 0;i < pch->size;i++)
	{
		if (pch->array[i] == x)
		{
			return i;
		}
	}
	return -1;
}

void seqlistrelease(SL* pch, SLdatetype pos)
{
	assert(pch);
	int end = pch->size - 1;
	int j = pos;
	while (j < end)
	{
		pch->array[j] = pch->array[j + 1];
		j++;
	}
	pch->size--;
}